package com.csf.service.login;

import com.csf.common.utils.Frame;
import com.csf.service.login.api.LoginService;
import com.csf.service.login.message.TestMessage.Test;
import com.csf.sr.api.AbstractService;
import com.csf.sr.api.ServiceRegistry;
import com.google.protobuf.InvalidProtocolBufferException;

public class LoginServiceImpl  extends AbstractService implements LoginService{

	private ServiceRegistry serviceRegistry;
	
	private int serviceId;
	
	@Override
	public void destroy() {
		serviceRegistry.unregister(serviceId);
		System.out.println("UnRegistered with Login Service from Service Registry");
		
	}

	@Override
	public void handleMessage(Frame frame) {
		Test t = null;
		try {
			t = Test.parseFrom(frame.getMessageBytes());
		} catch (InvalidProtocolBufferException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("Message from Client : id " + t.getId() + "name"
				+ t.getName());
	
	}

	@Override
	public void init() {
		serviceId = serviceRegistry.register(this, LoginService.class);
		System.out.println("Registered Login Service in Service Registry");
		
	}

	public void setServiceRegistry(ServiceRegistry serviceRegistry) {
		this.serviceRegistry = serviceRegistry;
	}
	
	

}
